﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Application.Admin.Sight
{
    public class SightPointAreaService : ISightPointAreaService
    {
        Domain.Uow.IRepository<Domain.Entity.SightPointArea> sightAreaRepository;

        public SightPointAreaService(Domain.Uow.IRepository<Domain.Entity.SightPointArea> sightPointArea)
        {
            if (sightPointArea == null)
            {
                throw new ArgumentNullException("sightAreaRepository is null");
            }
            sightAreaRepository = sightPointArea;
        }

        public Domain.Entity.SightPointArea Add(Domain.Entity.SightPointArea add, Domain.Entity.User operUser)
        {
            if (add == null) return add;
            sightAreaRepository.Add(add);
            sightAreaRepository.Uow.Commit();
            return add;
        }

        public bool Delete(Domain.Entity.SightPointArea delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                delete.State = false;
                sightAreaRepository.Modify(delete);
                sightAreaRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(Domain.Entity.SightPointArea delete, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                sightAreaRepository.Delete(delete);
                sightAreaRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Delete(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = sightAreaRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                item.State = false;
                sightAreaRepository.Modify(item);
            }
            try
            {
                sightAreaRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool DeleteTrue(IList<int> idList, Domain.Entity.User operUser)
        {
            var res = false;
            var delete = sightAreaRepository.GetList(e => idList.Contains(e.Id));
            foreach (var item in delete)
            {
                sightAreaRepository.Delete(item);
            }
            try
            {
                sightAreaRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public bool Modify(Domain.Entity.SightPointArea modify, Domain.Entity.User operUser)
        {
            var res = false;
            try
            {
                sightAreaRepository.Modify(modify);
                sightAreaRepository.Uow.Commit();
                res = true;
            }
            catch (Exception ex)
            {
            }
            return res;
        }

        public Domain.Entity.SightPointArea Get(int id)
        {
            var data = sightAreaRepository.Get(id);
            return data;
        }

        public IQueryable<Domain.Entity.SightPointArea> GetList()
        {
            var data = sightAreaRepository.GetList();
            return data;
        }

    }
}
